<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="text" />
    <script>
        const text = document.getElementById("text")

        function debounce(fn, wait = 1000) {
            let timer = null
            return function () {
                if (timer) clearTimeout(timer);
                timer = setTimeout(() => {
                    console.log(this)
                    fn.call(this, ...arguments)
                }, wait)
            }
        }

        /*
            arguments
            function a() {
                console.log(arguments)
                return () => {
                    console.log(arguments)
                }
            }
            a(1,2,3)(4,5,6)
        */
        function throttle(fn, wait = 1000) {
            let now = new Date()
            return function () {
                let pre = new Date()
                if (pre - now > wait) {
                    fn.call(this, ...arguments)
                    now = new Date()
                }
            }
        }
        text.addEventListener("keyup", debounce(() => {
            console.log(1)
        }))
    </script>
</body>

</html>